`:top
The `!Java Modeling Language`! (`!JML`!) is a `F33f`_`[specification language`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Specification_language]`_`f for `F33f`_`[Java`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_(programming_language)]`_`f programs, using `F33f`_`[Hoare style`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Hoare_logic]`_`f `F33f`_`[pre-`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Precondition]`_`f and `F33f`_`[postconditions`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Postcondition]`_`f and `F33f`_`[invariants`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Invariant_(computer_science)]`_`f, that follows the `F33f`_`[design by contract`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Design_by_contract]`_`f paradigm. Specifications are written as `F33f`_`[Java annotation`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_annotation]`_`f comments to the source files, which hence can be compiled with any Java `F33f`_`[compiler`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Compiler]`_`f.
Various verification tools, such as a runtime assertion checker and the Extended Static Checker (`F33f`_`[ESC/Java`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ESC/Java]`_`f) aid development.
>>Contents
• `F0af`_`[Overview`#overview]`_`f
• `F0af`_`[Syntax`#syntax]`_`f
• `F0af`_`[Tool support`#tool-support]`_`f
• `F0af`_`[References`#references]`_`f
• `F0af`_`[External links`#external-links]`_`f
-─
>>Overview
JML is a behavioural interface specification language for Java modules. JML provides `F33f`_`[semantics`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Semantics]`_`f to formally describe the behavior of a Java module, preventing ambiguity with regard to the module designers' intentions. JML inherits ideas from `F33f`_`[Eiffel`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Eiffel_(programming_language)]`_`f, `F33f`_`[Larch`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Larch_family]`_`f and the `F33f`_`[Refinement Calculus`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Refinement_Calculus]`_`f, with the goal of providing rigorous formal semantics while still being accessible to any Java programmer. Various tools are available that make use of JML's behavioral specifications. Because specifications can be written as annotations in Java program files, or stored in separate specification files, Java modules with JML specifications can be compiled unchanged with any Java compiler.
>>Syntax
JML specifications are added to Java code in the form of annotations in comments. Java comments are interpreted as JML annotations when they begin with an @ sign. That is, comments of the form
`B100`F9d9 //@ <JML specification>`f`b
or
`B100`F9d9 /*@ <JML specification> @*/`f`b
Basic JML syntax provides the following keywords
`!`B100`F9d9requires`f`b`!
Defines a `F33f`_`[precondition`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Precondition]`_`f on the `F33f`_`[method`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Method_(computer_science)]`_`f that follows.
`!`B100`F9d9ensures`f`b`!
Defines a `F33f`_`[postcondition`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Postcondition]`_`f on the method that follows.
`!`B100`F9d9signals`f`b`!
Defines a postcondition for when a given `F33f`_`[Exception`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Exception_handling]`_`f is thrown by the method that follows.
`!`B100`F9d9signals_only`f`b`!
Defines what exceptions may be thrown when the given precondition holds.
`!`B100`F9d9assignable`f`b`!
Defines which fields are allowed to be assigned to by the method that follows.
`!`B100`F9d9pure`f`b`!
Declares a method to be side effect free (like `B100`F9d9assignable \\nothing`f`b but can also throw exceptions). Furthermore, a pure method is supposed to always either terminate normally or throw an exception.
`!`B100`F9d9invariant`f`b`!
Defines an `F33f`_`[invariant property of the class`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Class_invariant]`_`f.
`!`B100`F9d9loop_invariant`f`b`!
Defines a `F33f`_`[loop invariant`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Loop_invariant]`_`f for a loop.
`!`B100`F9d9also`f`b`!
Combines specification cases and can also declare that a method is inheriting specifications from its supertypes.
`!`B100`F9d9assert`f`b`!
Defines a JML `F33f`_`[assertion`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Assertion_(computing)]`_`f.
`!`B100`F9d9spec_public`f`b`!
Declares a protected or private variable public for specification purposes.
Basic JML also provides the following expressions
`!`B100`F9d9\\result`f`b`!
An identifier for the return value of the method that follows.
`!`B100`F9d9\\old(<expression>)`f`b`!
A modifier to refer to the value of the `B100`F9d9<expression>`f`b at the time of entry into a method.
`!`B100`F9d9(\\forall <decl>; <range-exp>; <body-exp>)`f`b`!
The `F33f`_`[universal quantifier`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Universal_quantifier]`_`f.
`!`B100`F9d9(\\exists <decl>; <range-exp>; <body-exp>)`f`b`!
The `F33f`_`[existential quantifier`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Existential_quantifier]`_`f.
`!`B100`F9d9a ==> b`f`b`!
`B100`F9d9a`f`b implies `B100`F9d9b`f`b
`!`B100`F9d9a <== b`f`b`!
`B100`F9d9a`f`b is implied by `B100`F9d9b`f`b
`!`B100`F9d9a <==> b`f`b`!
`B100`F9d9a`f`b if and only if `B100`F9d9b`f`b
as well as standard `F33f`_`[Java syntax`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Java_syntax]`_`f for logical and, or, and not. JML annotations also have access to Java objects, object methods and operators that are within the scope of the method being annotated and that have appropriate visibility. These are combined to provide formal specifications of the properties of classes, fields and methods. For example, an annotated example of a simple banking class may look like
`B100`F9d9public class BankingExample`f`b
`B100`F9d9{`f`b
`B100`F9d9`f`b
`B100`F9d9 public static final int MAX_BALANCE = 1000;`f`b
`B100`F9d9 private /*@ spec_public @*/ int balance;`f`b
`B100`F9d9 private /*@ spec_public @*/ boolean isLocked = false;`f`b
`B100`F9d9`f`b
`B100`F9d9 //@ public invariant balance >= 0 && balance <= MAX_BALANCE;`f`b
`B100`F9d9`f`b
`B100`F9d9 //@ assignable balance;`f`b
`B100`F9d9 //@ ensures balance == 0;`f`b
`B100`F9d9 public BankingExample()`f`b
`B100`F9d9 {`f`b
`B100`F9d9 this.balance = 0;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 //@ requires 0 < amount && amount + balance < MAX_BALANCE;`f`b
`B100`F9d9 //@ assignable balance;`f`b
`B100`F9d9 //@ ensures balance == \\old(balance) + amount;`f`b
`B100`F9d9 public void credit(final int amount)`f`b
`B100`F9d9 {`f`b
`B100`F9d9 this.balance += amount;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 //@ requires 0 < amount && amount <= balance;`f`b
`B100`F9d9 //@ assignable balance;`f`b
`B100`F9d9 //@ ensures balance == \\old(balance) - amount;`f`b
`B100`F9d9 public void debit(final int amount)`f`b
`B100`F9d9 {`f`b
`B100`F9d9 this.balance -= amount;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 //@ ensures isLocked == true;`f`b
`B100`F9d9 public void lockAccount()`f`b
`B100`F9d9 {`f`b
`B100`F9d9 this.isLocked = true;`f`b
`B100`F9d9 }`f`b
`B100`F9d9`f`b
`B100`F9d9 //@ requires !isLocked;`f`b
`B100`F9d9 //@ ensures \\result == balance;`f`b
`B100`F9d9 //@ also`f`b
`B100`F9d9 //@ requires isLocked;`f`b
`B100`F9d9 //@ signals_only BankingException;`f`b
`B100`F9d9 public /*@ pure @*/ int getBalance() throws BankingException`f`b
`B100`F9d9 {`f`b
`B100`F9d9 if (!this.isLocked)`f`b
`B100`F9d9 {`f`b
`B100`F9d9 return this.balance;`f`b
`B100`F9d9 }`f`b
`B100`F9d9 else`f`b
`B100`F9d9 {`f`b
`B100`F9d9 throw new BankingException();`f`b
`B100`F9d9 }`f`b
`B100`F9d9 }`f`b
`B100`F9d9}`f`b
Full documentation of JML syntax is available in the JML Reference Manual.
>>Tool support
A variety of tools provide functionality based on JML annotations. The Iowa State JML tools provide an assertion checking `F33f`_`[compiler`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Compiler]`_`f `B100`F9d9jmlc`f`b which converts JML annotations into runtime assertions, a documentation generator `B100`F9d9jmldoc`f`b which produces `F33f`_`[Javadoc`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Javadoc]`_`f documentation augmented with extra information from JML annotations, and a unit test generator `B100`F9d9jmlunit`f`b which generates `F33f`_`[JUnit`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=JUnit]`_`f test code from JML annotations.
Independent groups are working on tools that make use of JML annotations. These include:
• `F33f`_`[ESC/Java2`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=ESC/Java2]`_`f [1], an extended static checker which uses JML annotations to perform more rigorous static checking than is otherwise possible.
• OpenJML declares itself the successor of ESC/Java2.
• Daikon, a dynamic invariant generator.
• `F33f`_`[KeY`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=KeY]`_`f, which provides an open source theorem prover with a JML front-end and an `F33f`_`[Eclipse`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Eclipse_(software)]`_`f plug-in (JML Editing) with support for `F33f`_`[syntax highlighting`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Syntax_highlighting]`_`f of JML.
• Krakatoa, a static verification tool based on the Why verification platform and using the `F33f`_`[Coq`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Coq_(software)]`_`f proof assistant.
• JMLEclipse, a plugin for the Eclipse integrated development environment with support for JML syntax and interfaces to various tools that make use of JML annotations.
• Sireum/Kiasan, a symbolic execution based static analyzer which supports JML as a contract language.
• JMLUnit, a tool to generate files for running JUnit tests on JML annotated Java files.
• TACO, an open source program analysis tool that statically checks the compliance of a Java program against its Java Modeling Language specification.
>>References
• `F33f`_`[Gary T. Leavens`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Gary_T._Leavens]`_`f and Yoonsik Cheon. `*Design by Contract with JML`*; Draft tutorial.
• `F33f`_`[Gary T. Leavens`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Gary_T._Leavens]`_`f, Albert L. Baker, and Clyde Ruby. `*JML: A Notation for Detailed Design`*; in Haim Kilov, `F33f`_`[Bernhard Rumpe`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Bernhard_Rumpe]`_`f, and Ian Simmonds (editors), `*Behavioral Specifications of Businesses and Systems`*, Kluwer, 1999, chapter 12, pages 175-188.
• `F33f`_`[Gary T. Leavens`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Gary_T._Leavens]`_`f, Erik Poll, Curtis Clifton, Yoonsik Cheon, Clyde Ruby, David Cok, Peter Müller, Joseph Kiniry, Patrice Chalin, and Daniel M. Zimmerman. JML Reference Manual (DRAFT), September 2009. HTML
• `F33f`_`[Marieke Huisman`:/page/wikibook/entry.mu`zim=wikipedia_en_all_nopic_2025-08.zim|entry_path=Marieke_Huisman]`_`f, Wolfgang Ahrendt, Daniel Bruns, and Martin Hentschel. `*Formal specification with JML`*. 2014. download (CC-BY-NC-ND)
>>External links
• JML website
`c`F0af`_`[↑ Back to top`#top]`_`f`a